package day_2022_9_to_12.Day;

import java.util.ArrayList;
import java.util.List;

/**
 * @author haomin
 * @date 2022/09/05 23:32
 **/
public class Day3_9_Offer57_Ⅱ_FindContinuousSequence {
    class Solution {
        // 双指针
        public int[][] findContinuousSequence(int target) {
            List<int[]> res = new ArrayList<>();
            int l = 1, r = 2, sum = 0;
            while(l < r){
                sum = (l + r)*(r-l+1)/2;
                if(sum == target){
                    int[] ret = new int[r-l+1];
                    for(int i = l; i <= r; ++i){
                        ret[i-l] = i;
                    }
                    res.add(ret); l++;
                }else if(sum < target) r++;
                else l++;
            }
            return res.toArray(new int[res.size()][]);
        }
    }
}